/**
 * 路由扩展
 * */
import { RouteMeta, Router, useRouter } from 'vue-router'

export interface ExtraRouter extends Router {
  // 获取中文名
  getName<T = string | undefined>(): T
  getMeta<T = RouteMeta>(): T
  // 获取query
  getQuery<T = { [p: string]: string }>(): T
  // 获取params
  getParams<T = { [p: string]: string }>(): T
}

/**
 * 封装的路由
 * */
function useExtraRouter(): ExtraRouter {
  return {
    ...useRouter(),
    getName<T>() {
      return this.currentRoute.value.meta.name as T
    },
    getMeta<T>() {
      return this.currentRoute.value.meta as T
    },
    getQuery<T>() {
      return this.currentRoute.value.query as T
    },
    getParams<T>() {
      return this.currentRoute.value.params as T
    },
  }
}

export default useExtraRouter
